//
//  WLGP_ShopItemCollectionViewCell.m
//  录音转文字助手
//
//  Created by 王亮 on 2020/9/9.
//  Copyright © 2020 录音转文字助手. All rights reserved.
//

#import "WLGP_ShopItemCollectionViewCell.h"
#import "DLStore.h"
@interface WLGP_ShopItemCollectionViewCell ()
@property(strong,nonatomic) SKProduct *product;

@property(nonatomic,strong) UILabel *titleLabel;
@property(nonatomic,strong) UILabel *desc_label;
@property(nonatomic,strong) UIButton *subscriptions_button;
@end
@implementation WLGP_ShopItemCollectionViewCell

-(void)bind_row_data:(WLBaseCollectionViewLayerRow *)sender{
    _product = sender.data;
    if ([_product.productIdentifier isEqualToString:comXII]){
        [self.subscriptions_button setBackgroundColor:[UIColor redColor]];
    } else {
        [self.subscriptions_button setBackgroundColor:[UIColor colorWithWhite:1 alpha:0.5f]];
    }
//    self.subscriptions_button.layer.borderColor = HexColor(@"158DF3").CGColor;
//    self.subscriptions_button.layer.borderWidth = 3;
//    self.subscriptions_button.layer.shadowOpacity = 0.8f;
//    self.subscriptions_button.layer.shadowRadius = 8.f;
//    self.subscriptions_button.layer.shadowOffset = CGSizeMake(0,0);
//    self.subscriptions_button.layer.shadowColor = HexColor(@"158DF3").CGColor;
}
-(void)bind_delegate:(id)sender{
    self.delegate = sender;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = UIColor.redColor;

        [self addSubview:self.subscriptions_button];

        
        [self.subscriptions_button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.insets(UIEdgeInsetsMake(5, 35, 5, 35));
        }];
        
        [self.subscriptions_button addSubview:self.titleLabel];
        [self.subscriptions_button addSubview:self.desc_label];
        
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.subscriptions_button);
            make.left.mas_equalTo(self.subscriptions_button).mas_offset(40);
        }];
        [self.desc_label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.subscriptions_button);
            make.right.mas_equalTo(self.subscriptions_button).mas_offset(-40);
        }];
    }
    return self;
}

-(void)goPay{
    [SVProgressHUD showMask_wl];
    [[DLStore singletonMod] dl_addPayment:self.product.productIdentifier success:^(SKPaymentTransaction * _Nonnull transaction) {
        NSLog(@"%@",transaction);
        [SVProgressHUD showSuccess_wl:@"操作成功"];
        if ([self.delegate respondsToSelector:@selector(wl_pay_sure_end:)]){
            [self.delegate wl_pay_sure_end:Guide_Close_Type_Sure];
        }
    } failure:^(SKPaymentTransaction * _Nonnull transaction, NSError * _Nonnull error) {
        [SVProgressHUD showError_wl:@"操作失败"];
        if ([self.delegate respondsToSelector:@selector(wl_pay_fail_end:)]){
            [self.delegate wl_pay_fail_end:Guide_Close_Type_Failure];
        }
    }];
}


-(UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.textColor = UIColor.redColor;
        _titleLabel.font = [UIFont systemFontOfSize:19];
#if DEBUG
        _titleLabel.text = @"ceshi";
#endif
    }
    return _titleLabel;
}


-(UILabel *)desc_label{
    if (!_desc_label){
        _desc_label = [[UILabel alloc]init];
        _desc_label.textColor = UIColor.redColor;
        _desc_label.font = [UIFont systemFontOfSize:19];
#if DEBUG
        _desc_label.text = @"ceshi/yue";
#endif
    }
    return _desc_label;
}

-(UIButton *)subscriptions_button{
    if (!_subscriptions_button){
        _subscriptions_button = [[UIButton alloc]init];
        _subscriptions_button.layer.cornerRadius = (self.frame.size.height - 10)/2.f;
        [_subscriptions_button setBackgroundColor:UIColor.whiteColor];
        [_subscriptions_button addTarget:self action:@selector(goPay) forControlEvents:UIControlEventTouchUpInside];
    }
    return _subscriptions_button;;
}

@end

@implementation WLGP_ShopItemCollectionViewCellModel



@end
